﻿using GrainManage.Entities.Column;
using System;
using System.Collections.Generic;

namespace GrainManage.Server.Business
{
    public class ColumnBusiness : BaseBusiness, GrainManage.Interface.IColumn
    {
        //************************************************POST************************************************
        public OutputGetHeader GetHeader(InputGetHeader input)
        {
            var result = new OutputGetHeader();
            try
            {
                var service = ObjectFactory.ColumnService;
                result.Header = service.GetHeader(input.ColumnName);
                if (string.IsNullOrEmpty(result.Header))
                {
                    SetResponse(StatusCode.NoData, input, result);
                }
                else
                {
                    SetResponse(StatusCode.Success, input, result);
                }
            }
            catch (Exception e)
            {
                SetResponse(StatusCode.Failed, input, result, e);

            }

            return result;
        }

        public OutputGetColumnHeader GetColumnHeader(InputGetColumnHeader input)
        {
            var result = new OutputGetColumnHeader();
            try
            {
                var service = ObjectFactory.ColumnService;
                var columns = service.Get(input, result);
                result.Columns = new Dictionary<string, string>(columns.Count);
                foreach (var column in columns)
                {
                    result.Columns[column.ColumnName] = column.Header;
                }

                if (result.Columns.Count == 0)
                {
                    SetResponse(StatusCode.NoData, input, result);
                }
                else
                {
                    SetResponse(StatusCode.Success, input, result);
                }
            }
            catch (Exception e)
            {
                SetResponse(StatusCode.Failed, input, result, e);

            }

            return result;
        }
    }
}
